﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    /// <summary>
    /// 获取个人的新消息数量
    /// </summary>
    class GetNewMessageCount4UserAction : GetAction<GetNewMessageCount4UserParams,
        GetNewMessageCount4UserResult>
    {
        protected override ActionResult<GetNewMessageCount4UserResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetNewMessageCount4UserParams opParams)
        {
            ServiceResult<Model.Data.NewMessageCount> serviceResult = new MessageService().GetNewMessageCount(opParams.UserId);

            GetNewMessageCount4UserResult actionResult = new GetNewMessageCount4UserResult();
            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                actionResult.SystemNoticeCount = serviceResult.Data.SystemNotice;
                actionResult.ActivityFeedbackCount = serviceResult.Data.ActivityFeedback;
                actionResult.FriendsMessageCount = serviceResult.Data.FriendsMessage;

                return new ActionResult<GetNewMessageCount4UserResult>("1.0", true, ErrorCode.NoError,
                            ErrorCode.ToString(ErrorCode.NoError), actionResult);
            }
            return new ActionResult<GetNewMessageCount4UserResult>("1.0", false, serviceResult.ErrorCode,
                ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }

    public class GetNewMessageCount4UserResult
    {
        public int SystemNoticeCount { get; set; }
        public int ActivityFeedbackCount { get; set; }
        public int FriendsMessageCount { get; set; }
    }

    public class GetNewMessageCount4UserParams : IActionParams
    {
        public int UserId { get; set; }

        public void ParseQueryString(System.Web.HttpRequest request)
        {
            UserId = Convert.ToInt32(request.QueryString["op:userid"]);
        }

        public void ParseForm(System.Web.HttpRequest request)
        {
            UserId = Convert.ToInt32(request.Form["op:userid"]);
        }
    }
}
